    //
//  ExampleViewController.m
//  Leaves
//
//  Created by Tom Brow on 4/18/10.
//  Copyright 2010 Tom Brow. All rights reserved.
//

#import "ImageController.h"
#import "Utilities.h"

@interface ImageController ()

@end

@implementation ImageController

- (NSMutableArray *)images
{
    if (_images == nil) {
        self.images =[NSMutableArray array];
    }
    return _images;
}

- (NSMutableArray *)titleArray
{
    if (_titleArray == nil) {
        self.titleArray =[NSMutableArray array];
    }
    return _titleArray;
}

- (id)initWithImages:(NSMutableArray *)images
{
    if (self = [super init]) {

        self.images = images;
    }
    return self;
}


#pragma mark LeavesViewDataSource
- (NSUInteger)numberOfPagesInLeavesView:(LeavesView*)leavesView {
	return _images.count;
    
}


- (void)renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx {
	UIImage *image = [_images objectAtIndex:index];
    NSLog(@"%ld",(unsigned long)index);
    self.navigationItem.title = self.titleArray[index];
	CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);
	CGAffineTransform transform = aspectFit(imageRect,
											CGContextGetClipBoundingBox(ctx));
	CGContextConcatCTM(ctx, transform);
	CGContextDrawImage(ctx, imageRect, [image CGImage]);   
}


@end
